iT邦幫忙

0

[筆記]android 版本問題

deh 2020-02-23 11:30:161372 瀏覽
  • 分享至 

  • xImage
  •  

精準延時呼叫

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        int offset = 10 * 1000;//間隔時間10s
        long triggerAtTime = SystemClock.elapsedRealtime() + offset;
        Intent i = new Intent(this, ForegroundService.class);
        PendingIntent mPendingIntent = PendingIntent.getService(this, 0, i, 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {            alarmManager.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, mPendingIntent);
            Log.i(TAG, "API 23+ ");
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, mPendingIntent);
            Log.i(TAG, "API 19+ ");
        } else {
            alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, offset, mPendingIntent);
            Log.i(TAG, "API 19- ");
        }

開機啟動服務

AndroidManifest加入
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            context.startForegroundService(i);
        }else {
            context.startService(i);
        }

連結http網頁需在AndroidManifest加入

android:usesCleartextTraffic="true"

android 6 以前的webView無法吃ES6的JS


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言